package dev.entao.html

import dev.entao.page.PageConst

fun FormTag.needsValidation() {
    classAdd("needs-validation")
    val formId = this.idx
    script {
        """
            client.formOnSubmitById('$formId');
        """.trimIndent()
    }
}

var ImageTag.dataSrcLarge: String
    get() = attrMap[PageConst.DATA_SRC_LARGE] ?: ""
    set(value) {
        attrMap[PageConst.DATA_SRC_LARGE] = value
        onclick = "client.showLargeImageById('${this.idx}')"
    }

var AnchorTag.dataConfirm: String
    get() = attrMap[PageConst.DATA_CONFIRM] ?: ""
    set(value) {
        attrMap[PageConst.DATA_CONFIRM] = value
        onclick = "client.showConfirmById('${this.idx}')"
    }
var ButtonTag.dataConfirm: String
    get() = attrMap[PageConst.DATA_CONFIRM] ?: ""
    set(value) {
        attrMap[PageConst.DATA_CONFIRM] = value
        onclick = "client.showConfirmById('${this.idx}')"
    }

var ButtonTag.dataModal: String
    get() = attrMap[PageConst.DATA_MODAL] ?: ""
    set(value) {
        attrMap[PageConst.DATA_MODAL] = value
        onclick = "client.showDialogById('${this.idx}');return false"
    }
var AnchorTag.dataModal: String
    get() = attrMap[PageConst.DATA_MODAL] ?: ""
    set(value) {
        attrMap[PageConst.DATA_MODAL] = value
        onclick = "client.showDialogById('${this.idx}');return false"
    }

var ButtonTag.dataScript: String
    get() = attrMap[PageConst.DATA_SCRIPT] ?: ""
    set(value) {
        attrMap[PageConst.DATA_SCRIPT] = value
        onclick = "client.evalElementAttr('${this.idx}')"
    }

var AnchorTag.dataScript: String
    get() = attrMap[PageConst.DATA_SCRIPT] ?: ""
    set(value) {
        attrMap[PageConst.DATA_SCRIPT] = value
        onclick = "client.evalElementAttr('${this.idx}');return false;"
    }